<?php
/**
 * 微信模板消息类
 * User: narnia
 * Date: 2017/5/19
 * Time: 11:24
 */
namespace LancerWechat;

class WechatTemplate extends WechatService
{
    public $key = 'template';

    /**
     * 获取模板消息列表
     */
    public function getList()
    {
        $url = $this->getUrl([
            '{access_token}' => $this->config['global']['access_token']
        ], [$this->key, 'getList']);
        $result = \LancerWechat\WechatFunction::curl($url);
        \LancerWechat\WechatLog::write($this->config['log']['path'], $result);
        return $result;
    }
    /**
     * 发送消息
     * @param   string  $json   json字符串
     */
    public function send(string $json)
    {
        if (is_array($json)) {
            $json = json_encode($json, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
        }
        $url = $this->getUrl([
            '{access_token}' => $this->config['global']['access_token']
        ], [$this->key, 'send']);
        $result = \LancerWechat\WechatFunction::curl($url, $json);
        \LancerWechat\WechatLog::write($this->config['log']['path'], $result);
        return $result;
    }


}